package com.bpmn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bpmn.common.annotation.ResponseInfoWrapper;
import com.bpmn.common.entity.ResponseResult;
import com.bpmn.common.pojo.PageResult;
import com.bpmn.system.domain.form.TenantForm;
import com.bpmn.system.domain.query.TenantQuery;
import com.bpmn.system.domain.vo.TenantVo;
import com.bpmn.system.service.ISysTenantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author rain
 */
@Tag(name = "租户管理")
@RestController
@RequiredArgsConstructor
@ResponseInfoWrapper
@RequestMapping("/system/tenant")
public class SysTenantController {

    private final ISysTenantService tenantService;

    @Operation(summary = "获取租户列表")
    @GetMapping("/list")
    public PageResult<TenantVo> list(TenantQuery query) {
        IPage<TenantVo> tenantVoIPage = tenantService.listTenant(query);
        return new PageResult<>(tenantVoIPage.getRecords(), tenantVoIPage.getTotal());

    }

    @Operation(summary = "新增租户")
    @PostMapping
    public Boolean add(@RequestBody TenantForm tenant) {
        tenantService.addTenant(tenant);
        return true;
    }

    @Operation(summary = "修改租户")
    @PutMapping
    public Boolean edit(@RequestBody TenantForm tenant) {
        tenantService.updateTenant(tenant);
        return true;
    }

    @Operation(summary = "删除租户")
    @DeleteMapping("/{id}")
    public Boolean remove(@PathVariable String id) {
        tenantService.deleteTenant(id);
        return true;
    }

    @Operation(summary = "生成AppSecret")
    @GetMapping("/generateSecret")
    public ResponseResult<String> generateSecret() {
        return ResponseResult.successStr(tenantService.generateSecret());
    }
} 